package com.pearl.generator.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author TangDan
 * @version 1.0
 * @since 2022/7/7
 */
@Slf4j
@Configuration
@EnableSwagger2WebMvc
public class Swagger2Configuration {
    /**
     * 文档
     *
     * @return Docket
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("代码生成器", "明珠科技有限公司", "1.0.0"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.pearl.generator")) // 扫描路径
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 文档信息
     *
     * @return ApiInfo
     */
    private ApiInfo apiInfo(String title, String description, String version) {
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .version(version)
                .build();
    }
}